//var Nestable = function () {
(function () {

	var updateOutput = function (e) {

	var list = e.length ? e : $(e.currentTarget),
		 output = list.data('output');
		if (window.JSON) {
			output.val(window.JSON.stringify(list.nestable('serialize'))); //, null, 2));
			output.val(window.JSON.stringify(list.nestable('serialize'))); //, null, 2));
		} else {
			output.val('JSON browser support required for this demo.');
		}
	};


	// activate Nestable for list 1
	$('#nestable_list_1').nestable({
	  group: 1
	})
	  .on('change', updateOutput);

	// output initial serialised data
	updateOutput($('#nestable_list_1').data('output', $('#nestable_list_1_output')));

	$('#nestable_list_menu').on('click', function (e) {
	  var target = $(e.target),
			action = target.data('action');
	  if (action === 'expand-all') {
			$('.dd').nestable('expandAll');
	  }
	  if (action === 'collapse-all') {
			$('.dd').nestable('collapseAll');
	  }
	});
	
	//Leon eidt: "icon-plus" changed to "icon-sun" (this icon doesn't mean anything
//	var test = jQuery('.widget .widget-title .icon-sun');
//	jQuery('.widget .widget-title .icon-plus').click(function () {
//	  var el = jQuery(this).parents(".widget").children(".widget-body");
//	  if (jQuery(this).hasClass("icon-chevron-down")) {
//			jQuery(this).removeClass("icon-chevron-down").addClass("icon-chevron-up");
//			el.slideUp(200);
//	  } else {
//			jQuery(this).removeClass("icon-chevron-up").addClass("icon-chevron-down");
//			el.slideDown(200);
//	  }
//	});

	//Leon eidt: trigger dd-handle hover evnt
//	var ddhandle = $('.dd-handle')
//	ddhandle.hover(function(){
//		ddhandle.children(".dd-display").css({
//			"background-color": "yellow",
//			"font-weight": "bolder"
//		});
//	});
})();